package com.songshu.sb.controller;

import com.songshu.sb.dto.ApiResult;
import com.songshu.sb.dto.BusinessException;
import com.songshu.sb.service.impl.JdbcTemplateTestServiceImpl;
import com.songshu.sb.vo.SystemVersion;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping(path = "/api/v1")
@ConditionalOnProperty(name = "api.enabled", havingValue = "true")
public class ApiController {

    @Autowired
    private SystemVersion sv;
    @Autowired
    private JdbcTemplateTestServiceImpl jdbcTemplateTestService;


    @GetMapping(value = "version")
    public ApiResult getVersion(){
        SystemVersion tsv = new SystemVersion(sv.getVersion(), sv.getSystemDescription());
        return ApiResult.success(tsv);
    }

    @GetMapping(value = "test")
    public ApiResult testBusinessException(){
        throw new BusinessException(113, "业务异常……");
    }

    @GetMapping(value = "testJdbctemplate")
    public ApiResult testJdbctemplate(){
        List<Map<String, Object>> maps = jdbcTemplateTestService.querySysUser();
        return ApiResult.success(maps);
    }

}